import { WebView, View } from "@tarojs/components";
import Taro, { useDidShow, useRouter } from "@tarojs/taro";
import { useEffect, useState } from "react";
import { getLicense } from "@/services/openApi";
import { useLanguageStore } from "@/hooks";
import { observer } from "mobx-react-lite";

const LicenseScreen = () => {
  const { params } = useRouter();
  const language = useLanguageStore();
  const [url, setUrl] = useState("");
  useEffect(() => {
    Taro.setNavigationBarColor({ frontColor: '#000000', backgroundColor: '#ffffff' })
  }, [])

  useDidShow(async () => {
    const res = await getLicense({
      type: params.type!,
      language: language.key,
    });
    if (res.success) {
      setUrl(res.data.terms_url);
    }
  });

  return (
    <WebView src={url} />
  );
};

export default observer(LicenseScreen);
